<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/*
 * admin 路由
 */
include base_path('routes/admin/admin.php');
Route::get('/', function () {
//    dd(\Illuminate\Support\Facades\Redis::connection());
//    dd(app('redis')->connection());
//    dd(app('redis.connection'));
    //上面方法均可用
    return '网站全局访问量：' . \Illuminate\Support\Facades\Redis::get('site_total_visits');
});
Route::get('/posts/demo',[Controllers\PostController::class, 'demo'])->name('demo1');
Route::get('/posts/popular', [Controllers\PostController::class, 'popular']);
//Route::get('/posts/{post}', [Controllers\PostController::class, 'show']);
Route::get('/posts/{id}', [Controllers\PostController::class, 'show'])->where('id','[0-9]+');
//include base_path('routes/home/home.php');


//路由参数
//必填参数
Route::get('user1/{id}',function ($id){
    return 'User'.$id;
});
//多个参数
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
    //
    return $postId.'|'.$commentId;
});
//可选参数
Route::get('user2/{name?}',function($name=null){
    return $name;
});
Route::get('user3/{name?}',function($name='haix'){
    return $name;
});
/**
 * 正则表达式约束
 */
/**
 * 只能英文
 */
Route::get('user4/{name}',function($name){
    return $name;
})->where('name','[A-Za-z]+');

/**
 * 只能数字
 */
Route::get('user5/{name}',function ($name){
    return $name;
})->where('name','[0-9]+');
/**
 *
 */
Route::get('user6/{id}/{name}',function($id,$name){
    return $id.'|'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);

//方便模式
Route::get('user7/{id}/{name}',function ($id,$name){
    return $id.'|'.$name;
})->whereNumber('id')->whereAlpha('name');

//Route::get('user8/{name}',function ($name){
//    return $name;
//})->whereAlphaNumeric('name');  //可以为数字和字母  //有问题
//  报错信息BadMethodCallException
//Method Illuminate\Routing\Route::whereAlphaNumeric does not exist.


Route::get('user9/{id}',function($id){
    return $id;
})->whereUuid('id');  //意思不明确   有人帮忙
//  匹配
//数字或者a-f或者A-F （x位）

/**
 * 全局约束
 */
//已经定义了pattern id只能为数字
Route::get('user10/{id}',function ($id){
    return $id;
});

//编码正斜杠字符
Route::get('/serach/{search}',function($search){
    return $search;
})->where('search','.*'); //没懂

/**
 * 路由命名
 */
Route::get('user11/profile',function (){
    return redirect()->route('profile');
})->name('users');

Route::get('user12/profile',[Controllers\DemoController::class,'index'])->name('profile');

Route::get('user13/{id}/profile',function ($id){
    dd(route('profile3',['id'=>1,'photo'=>'yes']));
})->name('profile1');

Route::get('user14/{id}',function($id){

})->name('profile2');

Route::get('user16',function(){

})->name('profile3');

/**
 * 检查当前路由
 */
Route::get('user16',function(){

})->name('profile3');
/**
 * 中间件
 */
//Route::middleware(['first','second'])->group(function(){
//    Route::get('/',function (){
//
//    });
//});
/**
 * 子域名路由
 */
Route::domain('www.baidu.com')->group(function (){
    Route::get('/',function(){

    });
});
/**
 * 路由前缀
 */
Route::prefix('abc')->group(function(){
    Route::get('/',function (){
        echo 123;
    });
});
/**
 * 路由名称前缀
 */
Route::name('abb.')->group(function(){
    Route::get('/users',function(){
        echo 111;
    })->name('users1');
});

